package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.CarInfo;
import cn.wolfcode.crm.mapper.CarInfoMapper;
import cn.wolfcode.crm.query.CarInfoQueryObject;
import cn.wolfcode.crm.service.ICarInfoService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarInfoServiceImpl implements ICarInfoService{
    @Autowired
    private CarInfoMapper mapper;

    public void save(CarInfo entity) {
        mapper.insert(entity);
    }

    public void update(CarInfo entity) {
        mapper.updateByPrimaryKey(entity);
    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public CarInfo get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<CarInfo> getAll() {
        return mapper.selectAll();
    }

    public PageResult query(CarInfoQueryObject qo) {
        int count = mapper.queryForCount(qo);
        if(count==0){
            return new PageResult(0,null);
        }
        List<CarInfo> list = mapper.queryForList(qo);
        return new PageResult(count,list);
    }
}
